package com.wcl.demo.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wcl.demo.R;


/**
 * Created by dllo on 15/11/21.
 */
public class MakeGroupActivity extends Activity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
    private RelativeLayout make_group_chex_down_relat;
    private ImageView activity_make_group_bac_Iv;
    //是否公开/是否开放成员邀请
    private CheckBox open_or_close_Chx, if_openChex;
    private TextView make_group_save_textBtn;
    private EditText activity_make_group_edTv, activity_group_infor_edTv;
    private String groupName, desc;
    private boolean chex = false;//第一个chexbox的值
    private boolean ifOpen = false;//第二个chexbox的值
    private String wayKey;//跳转之后用于判断使用哪种建群方式


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_make_group);
        initView();
    }

    private void initView() {
        make_group_chex_down_relat = (RelativeLayout) findViewById(R.id.make_group_chex_down_relat);

        make_group_save_textBtn = (TextView) findViewById(R.id.make_group_save_textBtn);
        make_group_save_textBtn.setOnClickListener(this);

        activity_make_group_edTv = (EditText) findViewById(R.id.activity_make_group_edTv);

        activity_group_infor_edTv = (EditText) findViewById(R.id.activity_group_infor_edTv);


        activity_make_group_bac_Iv = (ImageView) findViewById(R.id.activity_make_group_bac_Iv);
        activity_make_group_bac_Iv.setOnClickListener(this);
        open_or_close_Chx = (CheckBox) findViewById(R.id.open_or_close_Chx);
        open_or_close_Chx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                //选中之后设置第二个chex隐藏
                    make_group_chex_down_relat.setVisibility(View.GONE);
                    Log.i("lanou" , "创建公开群");
                    ifOpen = true;
                } else {
                    make_group_chex_down_relat.setVisibility(View.VISIBLE);
                    ifOpen = false;
                }

            }
        });
        if_openChex = (CheckBox) findViewById(R.id.if_openChex);
        if_openChex.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    chex = true;
                } else {
                    chex = false;
                }

            }
        });

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.activity_make_group_bac_Iv:
                finish();
                break;
            case R.id.make_group_save_textBtn:
                initInfor();//获得群信息
                Intent intent = new Intent();
                intent.putExtra("groupName", groupName);
                intent.putExtra("desc", desc);
                if (chex) {//是否公开
                    wayKey = "1";//创建公开群
                    intent.putExtra("wayKey", wayKey);
                } else {//是否开放成员邀请
                    wayKey = "2";//创建私有群
                    intent.putExtra("wayKey", wayKey);
                    intent.putExtra("ifOpen", ifOpen + "");
                    Log.i("shaco", ifOpen + "");


                    intent.putExtra("ifOpen", ifOpen+"");
                    Log.i("shaco",ifOpen+"");
                }
                intent.setClass(this, ChosePersonActivity.class);
                startActivity(intent);
                finish();
                    break;
                }
        }




    //获得群信息
    private void initInfor() {
        groupName = activity_make_group_edTv.getText().toString();//群名
        desc = activity_group_infor_edTv.getText().toString();//群简介

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    }
}
